package TAProgram;

public class Variable {
    String name;
    Boolean tempFlag; //1 is temp Variable
    ValueType valueType;
    String constStringValue;
    Integer constIntValue;
    Float constFloatValue;

    @Override
    public String toString() {
        String code = new String("");
        if(valueType == null){
            //是变量
            if(name != null) code += name;
        }else if(valueType == ValueType.STRINGTYPE){
            //是字符串常量
            code += constStringValue;
        }else if(valueType == ValueType.FLOAGTYPE){
            code += constFloatValue.toString();
        }else if(valueType == ValueType.INTTYPE){
            code += constIntValue.toString();
        }
        return code;
    }

    public Variable(String name, Boolean tempFlag) {
        this.name = name;
        this.tempFlag = tempFlag;
    }

    public Variable(String name) {
        this.name = name;
        this.tempFlag = false;
    }

    public Variable(Variable variable) {
        this.name = variable.name;
        this.valueType = variable.valueType;
        this.tempFlag = variable.tempFlag;
        this.constFloatValue = variable.constFloatValue;
        this.constIntValue = variable.constIntValue;
        this.constStringValue = variable.constStringValue;
    }

    public Variable(String name, Boolean tempFlag, ValueType valueType) {
        this.name = name;
        this.tempFlag = tempFlag;
        this.valueType = valueType;
    }

    public Variable(String name, Boolean tempFlag, ValueType valueType, String constStringValue) {
        this.name = name;
        this.tempFlag = tempFlag;
        this.valueType = valueType;
        this.constStringValue = constStringValue;
    }

    public Variable(String name, Boolean tempFlag, ValueType valueType, Integer constIntValue) {
        this.name = name;
        this.tempFlag = tempFlag;
        this.valueType = valueType;
        this.constIntValue = constIntValue;
    }

    public Variable(String name, Boolean tempFlag, ValueType valueType, Float constFloatValue) {
        this.name = name;
        this.tempFlag = tempFlag;
        this.valueType = valueType;
        this.constFloatValue = constFloatValue;
    }

    public String getName() {
        if(this.name == null){
            return "";
        }
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getTempFlag() {
        return tempFlag;
    }

    public void setTempFlag(Boolean tempFlag) {
        this.tempFlag = tempFlag;
    }

    public ValueType getValueType() {
        return valueType;
    }

    public void setValueType(ValueType valueType) {
        this.valueType = valueType;
    }

    public String getConstStringValue() {
        return constStringValue;
    }

    public void setConstStringValue(String constStringValue) {
        this.constStringValue = constStringValue;
    }

    public Integer getConstIntValue() {
        return constIntValue;
    }

    public void setConstIntValue(Integer constIntValue) {
        this.constIntValue = constIntValue;
    }

    public Float getConstFloatValue() {
        return constFloatValue;
    }

    public void setConstFloatValue(Float constFloatValue) {
        this.constFloatValue = constFloatValue;
    }
}
